"use strict";

/** @type {import('sequelize-cli').Migration} */
module.exports = {
  async up(queryInterface, Sequelize) {
    await queryInterface.removeColumn("users", "deadline");
    await queryInterface.removeColumn("users", "content");
    await queryInterface.removeColumn("users", "address");

    // 添加字段1
    await queryInterface.addColumn('users', 'password', {
      type: Sequelize.STRING,
      allowNull: false,
    });
    await queryInterface.addColumn('users', 'avatar', {
      type: Sequelize.STRING,
      allowNull: true,
    });

    // 修改字段
    await queryInterface.renameColumn('users', 'name', 'username');

    /**
     * Add altering commands here.
     *
     * Example:
     * await queryInterface.createTable('users', { id: Sequelize.INTEGER });
     */
  },

  async down(queryInterface, Sequelize) {
    // 如果需要回滚操作，可以在这里重新添加字段
    await queryInterface.addColumn("users", "deadline", {
      type: Sequelize.DATE,
      allowNull: true,
    });
    await queryInterface.addColumn("users", "content", {
      type: Sequelize.STRING,
      allowNull: true,
    });
    await queryInterface.addColumn("users", "address", {
      type: Sequelize.STRING,
      allowNull: true,
    });

    await queryInterface.removeColumn('users', 'password');
    await queryInterface.removeColumn('users', 'avatar');

    // 修改字段
    await queryInterface.renameColumn('users', 'username', 'name');

    // 继续添加需要回滚的字段...
  },
};
